package com.baize.channel.game.util;

import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import java.lang.reflect.InvocationTargetException;

public class RomUtil {
    private static final String KEY_EMUI_VERSION_CODE = "ro.build.hw_emui_api_level";
    private static final String KEY_FLYME_FLYME = "ro.meizu.setupwizard.flyme";
    private static final String KEY_FLYME_ICON_FALG = "persist.sys.use.flyme.icon";
    private static final String KEY_FLYME_PUBLISHED = "ro.flyme.published";
    private static final String KEY_FLYME_PUBLISH_FALG = "ro.flyme.published";
    private static final String KEY_FLYME_SETUP_FALG = "ro.meizu.setupwizard.flyme";
    private static final String KEY_MIUI_HANDY_MODE_SF = "ro.miui.has_handy_mode_sf";
    private static final String KEY_MIUI_REAL_BLUR = "ro.miui.has_real_blur";
    private static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code";
    private static final String KEY_VERSION_EMUI = "ro.build.version.emui";
    private static final String KEY_VERSION_FLYME = "ro.build.display.id";
    private static final String KEY_VERSION_GIONEE = "ro.gn.sv.version";
    private static final String KEY_VERSION_LENOVO = "ro.lenovo.lvp.version";
    private static final String KEY_VERSION_MIUI = "ro.miui.ui.version.name";
    private static final String KEY_VERSION_OPPO = "ro.build.version.opporom";
    private static final String KEY_VERSION_SMARTISAN = "ro.smartisan.version";
    private static final String KEY_VERSION_VIVO = "ro.vivo.os.version";
    private static final String KEY_VIVO_OS_NAME = "ro.vivo.os.name";
    private static final String KEY_VIVO_OS_VERSION = "ro.vivo.os.version";
    private static final String KEY_VIVO_ROM_VERSION = "ro.vivo.rom.version";
    public static final String ROM_EMUI = "EMUI";
    public static final String ROM_FLYME = "FLYME";
    public static final String ROM_LENOVO = "LENOVO";
    public static final String ROM_MIUI = "MIUI";
    public static final String ROM_OPPO = "OPPO";
    public static final String ROM_QIKU = "QIKU";
    public static final String ROM_SAMSUNG = "SAMSUNG";
    public static final String ROM_SMARTISAN = "SMARTISAN";
    public static final String ROM_VIVO = "VIVO";
    private static final String TAG = "RomUtil";
    public static final int VIVO_FILLET = 8;
    public static final int VIVO_NOTCH = 32;
    private static String sName;
    private static String sVersion;

    public static boolean isEmui() {
        return check(ROM_EMUI);
    }

    public static boolean isMiui() {
        return check(ROM_MIUI);
    }

    public static boolean isVivo() {
        return check(ROM_VIVO);
    }

    public static boolean isOppo() {
        return check(ROM_OPPO);
    }

    public static boolean isFlyme() {
        return check(ROM_FLYME);
    }

    public static boolean isQiku() {
        return check(ROM_QIKU) || check("360");
    }

    public static boolean isSmartisan() {
        return check(ROM_SMARTISAN);
    }

    public static String getName() {
        if (sName == null) {
            check("");
        }
        return sName;
    }

    public static String getVersion() {
        if (sVersion == null) {
            check("");
        }
        return sVersion;
    }

    public static boolean check(String rom) {
        if (sName != null) {
            return sName.equals(rom);
        }
        String prop = getProp(KEY_VERSION_MIUI);
        sVersion = prop;
        if (!TextUtils.isEmpty(prop)) {
            sName = ROM_MIUI;
        } else {
            String prop2 = getProp(KEY_VERSION_EMUI);
            sVersion = prop2;
            if (!TextUtils.isEmpty(prop2)) {
                sName = ROM_EMUI;
            } else {
                String prop3 = getProp(KEY_VERSION_OPPO);
                sVersion = prop3;
                if (!TextUtils.isEmpty(prop3)) {
                    sName = ROM_OPPO;
                } else {
                    String prop4 = getProp("ro.vivo.os.version");
                    sVersion = prop4;
                    if (!TextUtils.isEmpty(prop4)) {
                        sName = ROM_VIVO;
                    } else {
                        String prop5 = getProp(KEY_VERSION_SMARTISAN);
                        sVersion = prop5;
                        if (!TextUtils.isEmpty(prop5)) {
                            sName = ROM_SMARTISAN;
                        } else {
                            sVersion = Build.DISPLAY;
                            if (sVersion.toUpperCase().contains(ROM_FLYME)) {
                                sName = ROM_FLYME;
                            } else {
                                sVersion = "unknown";
                                sName = Build.MANUFACTURER.toUpperCase();
                            }
                        }
                    }
                }
            }
        }
        return sName.equals(rom);
    }

    /* JADX WARNING: Removed duplicated region for block: B:11:0x003b A[SYNTHETIC, Splitter:B:11:0x003b] */
    /* JADX WARNING: Removed duplicated region for block: B:18:0x0048 A[SYNTHETIC, Splitter:B:18:0x0048] */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static java.lang.String getProp(java.lang.String r9) {
        /*
            r4 = 0
            r2 = 0
            java.lang.Runtime r6 = java.lang.Runtime.getRuntime()     // Catch:{ IOException -> 0x0038, all -> 0x0045 }
            java.lang.StringBuilder r7 = new java.lang.StringBuilder     // Catch:{ IOException -> 0x0038, all -> 0x0045 }
            java.lang.String r8 = "getprop "
            r7.<init>(r8)     // Catch:{ IOException -> 0x0038, all -> 0x0045 }
            java.lang.StringBuilder r7 = r7.append(r9)     // Catch:{ IOException -> 0x0038, all -> 0x0045 }
            java.lang.String r7 = r7.toString()     // Catch:{ IOException -> 0x0038, all -> 0x0045 }
            java.lang.Process r5 = r6.exec(r7)     // Catch:{ IOException -> 0x0038, all -> 0x0045 }
            java.io.BufferedReader r3 = new java.io.BufferedReader     // Catch:{ IOException -> 0x0038, all -> 0x0045 }
            java.io.InputStreamReader r6 = new java.io.InputStreamReader     // Catch:{ IOException -> 0x0038, all -> 0x0045 }
            java.io.InputStream r7 = r5.getInputStream()     // Catch:{ IOException -> 0x0038, all -> 0x0045 }
            r6.<init>(r7)     // Catch:{ IOException -> 0x0038, all -> 0x0045 }
            r7 = 1024(0x400, float:1.435E-42)
            r3.<init>(r6, r7)     // Catch:{ IOException -> 0x0038, all -> 0x0045 }
            java.lang.String r4 = r3.readLine()     // Catch:{ IOException -> 0x0059, all -> 0x0056 }
            r3.close()     // Catch:{ IOException -> 0x0059, all -> 0x0056 }
            if (r3 == 0) goto L_0x0035
            r3.close()     // Catch:{ IOException -> 0x0051 }
        L_0x0035:
            r2 = r3
            r6 = r4
        L_0x0037:
            return r6
        L_0x0038:
            r1 = move-exception
        L_0x0039:
            if (r2 == 0) goto L_0x003e
            r2.close()     // Catch:{ IOException -> 0x0040 }
        L_0x003e:
            r6 = 0
            goto L_0x0037
        L_0x0040:
            r0 = move-exception
            r0.printStackTrace()
            goto L_0x003e
        L_0x0045:
            r6 = move-exception
        L_0x0046:
            if (r2 == 0) goto L_0x004b
            r2.close()     // Catch:{ IOException -> 0x004c }
        L_0x004b:
            throw r6
        L_0x004c:
            r0 = move-exception
            r0.printStackTrace()
            goto L_0x004b
        L_0x0051:
            r0 = move-exception
            r0.printStackTrace()
            goto L_0x0035
        L_0x0056:
            r6 = move-exception
            r2 = r3
            goto L_0x0046
        L_0x0059:
            r1 = move-exception
            r2 = r3
            goto L_0x0039
        */
        throw new UnsupportedOperationException("Method not decompiled: com.qk.plugin.js.shell.util.RomUtil.getProp(java.lang.String):java.lang.String");
    }

    public static boolean hasNotchScreen(Activity activity) {
        if (getInt("ro.miui.notch", activity) == 1 || hasNotchAtHuawei(activity) || hasNotchAtOPPO(activity) || hasNotchAtVivo(activity)) {
            return true;
        }
        return false;
    }

    public static int getInt(String key, Activity activity) {
        if (!isMiui()) {
            return 0;
        }
        try {
            Class SystemProperties = activity.getClassLoader().loadClass("android.os.SystemProperties");
            return ((Integer) SystemProperties.getMethod("getInt", String.class, Integer.TYPE).invoke(SystemProperties, new String(key), new Integer(0))).intValue();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return 0;
        } catch (NoSuchMethodException e2) {
            e2.printStackTrace();
            return 0;
        } catch (IllegalAccessException e3) {
            e3.printStackTrace();
            return 0;
        } catch (IllegalArgumentException e4) {
            e4.printStackTrace();
            return 0;
        } catch (InvocationTargetException e5) {
            e5.printStackTrace();
            return 0;
        }
    }

    public static boolean hasNotchAtHuawei(Context context) {
        String manufacturer = Build.MANUFACTURER;
        String brand = Build.BRAND;
        if (!"HUAWEI".equals(manufacturer) && !"HONOR".equals(brand)) {
            return false;
        }
        try {
            Class HwNotchSizeUtil = context.getClassLoader().loadClass("com.huawei.android.util.HwNotchSizeUtil");
            return ((Boolean) HwNotchSizeUtil.getMethod("hasNotchInScreen", new Class[0]).invoke(HwNotchSizeUtil, new Object[0])).booleanValue();
        } catch (Exception e) {
            return false;
        }
    }

    public static boolean hasNotchAtVivo(Context context) {
        boolean ret = false;
        if (!check(ROM_VIVO)) {
            return false;
        }
        try {
            Class FtFeature = context.getClassLoader().loadClass("android.util.FtFeature");
            ret = ((Boolean) FtFeature.getMethod("isFeatureSupport", Integer.TYPE).invoke(FtFeature, 32)).booleanValue();
        } catch (Exception e) {
        }
        return ret;
    }

    public static boolean hasNotchAtOPPO(Context context) {
        if (check(ROM_OPPO)) {
            return context.getPackageManager().hasSystemFeature("com.oppo.feature.screen.heteromorphism");
        }
        return false;
    }
}